#include "socket.hpp"
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
#include <unistd.h>

class HttpClient
{
public:
    HttpClient(const std::string &ip, uint16_t port) : _ip(ip), _port(port)
    {
        _sock = new NetWork::TcpSocket();
    }
    ~HttpClient()
    {
        _sock->CloseSockFd();
        delete _sock;
    }
    void Init()
    {
        if (!_sock->BuildConnectSocketMethod(_ip, _port))
        {
            std::cerr << "connect server failed, error code: " << errno << ", error message: " << strerror(errno) << std::endl;
        }
        std::cout << "client fd = " << _sock->GetSockFd() << std::endl;
        std::cout << "connect server success" << std::endl;
    }
    void AskCal()
    {
       // 处理业务
        std::string request = "hello world";
        _sock->Send(request);
    }

private:
    NetWork::Socket *_sock;
    uint16_t _port;
    std::string _ip;
};